#ifndef _MAC_H
#define _MAC_H

#include <mh/probe.h>
#include "carriage.h"
#include "sink_setting.h"
#include "camsetting.h"

/*
* create a machine object
*/
struct MACHINE *CreateMachine(unsigned char cam);
/*
* destroy a machine object
*/
void DestroyMachine(struct MACHINE *pmac);
/*
 * create probe data
 */
struct PROBE_DATA *MacCreateProbe(struct MACHINE *pmac);
/*
 * turn off/on green light
 * \param state: 0-off, 1-on
 */
int SwitchGreenLight(struct MACHINE *pmac, int state);
/*
* turn off/on yellow light
* \param state: 0-off, 1-on
*/
int SwitchYellowLight(struct MACHINE *pmac, int state);
/*
* turn off/on red light
* \param state: 0-off, 1-on
*/
int SwitchRedLight(struct MACHINE *pmac, int state);
/*
* turn off/on buzzer
* \param state: 0-off, 1-on
*/
int SwitchBuzzer(struct MACHINE *pmac, int state);
/*
* enable/disable driver of machine
* \param state: 0-disable, 1-enable(lock)
*/
int SwitchMacDriver(struct MACHINE *pmac, int state);
/*
* run the machine
* \param drt: 0-stop, 1-left, 2-right
* \param speed: between 1-100
*/
int MacRunMotor(struct MACHINE *pmac, int drt, int speed);
/*
* run the master rab or high roller
* \param speed: 0-stop, <0-reversal open, >0 normal run
*/
int MacRunRab(struct MACHINE *pmac, uchar speed, int pulse);
/*
* run the auxiliary rab or low roller
* \param speed: 0-stop, <0-reversal open, >0 normal run
*/
int MacRunRoller(struct MACHINE *pmac, int speed);
/*
* run the yarn feeder machine
* \param drt: 0-left, 1-right
* \param state: 0-off, 1-on
*/
int SwitchYarnFeeder(struct MACHINE *pmac, int drt, int state);
/*
* toggle state of machine
*/
int MacSendState(struct MACHINE *pmac, int state);
/*
 * get signal of rack
 * \param signal: filled out the signal state
 * \param size: sizeof(signal array)
*/
int MacGetRackSignal(struct MACHINE *pmac, unsigned char *signal, int size, short *needle);
/*
* wait for machine into given state
*/
int ChangeMonitorState(struct MACHINE *pmac, int state);
/*
 * è¿è¡çº¿ç¨
 */
void *RunMonitor(void *arg);
int MacRunThread(struct MACHINE *pmac);
/*
* start machine
*/
int MacStartMachine(struct MACHINE *pmac, PMAC_RESET pmac_reset);
/*
* unlock the knit row
*/
int MacUnlockRow(struct MACHINE *pmac);
/*
 * lock knit row
 */
int MacLockRow(struct MACHINE *pmac, int start, int end, int times);
/*
 * switch yarn
 */
int MacSwitchYarn(struct MACHINE *pmac, int yarn_switch);
/*
 * get running state of machine
 */
int GetMacRunState(struct MACHINE *pmac);
/*
 * check reset finished of machine
 */
int GetMacResetStep(struct MACHINE *pmac);
/*
 * check all data send to machine
 */
int MacProbeFinished(struct MACHINE *pmac);
/*
 * knit line changed of machine
 */
int MacLineChanged(struct MACHINE *pmac);
/*
 * set speed of motor on machine
 * param sect: from 0 to 31
 */
int MacSetMotorSpeed(struct MACHINE *pmac, unsigned int sect, unsigned char speed);
/*
 * send data of yarn_befor_set
 */
int MacSendYarnBeforeSet(struct MACHINE *pmac, char *data, uint num, uint offset);
/*
 * send sink param
 */
int MacSendCamParam(struct MACHINE *pmac, CAM_PIECE psa);
/*
 * send speed of machine
 */
int MacSendMacSpeed(struct MACHINE *pmac, uchar speed);
/*
 * send time of system
 */
int MacSendSysTime(struct MACHINE *pmac,  int set_time, int add_time, ushort lock);
/*
 * send type of machine
 */
int MacSendMachineType(struct MACHINE *pmac, ushort sys_type, ushort mac_type);
/*
 * send save data
 */
int MacSendSaveData(struct MACHINE *pmac, ushort data);


/***************************************************************************
 * all be feedback from machine in running below
 **************************************************************************/
/*
 * get communication of machine
 */
ushort MacGetCommunication(struct MACHINE *pmac);
/*
 * get start of economy
 */
ushort MacEconomyStart(struct MACHINE *pmac);
/*
 * get start of economy
 */
ushort MacEconomyEnd(struct MACHINE *pmac);
/*
 * get end of economy
 */
ushort MacEconomyTimes(struct MACHINE *pmac);
/*
 * get left of economy
 */
ushort MacEconomyLeft(struct MACHINE *pmac);
/*
 * get error code of machine
 */
ushort MacGetRunError(struct MACHINE *pmac);
/*
 * get needle of running
 */
short MacGetRunNeedle(struct MACHINE *pmac);
/*
 * get line of running
 */
short MacGetRunLine(struct MACHINE *pmac);
/*
 * get hangding of running
 */
char MacGetRockRunState(struct MACHINE *pmac);
/*
 * get state of handle
 */
int MacGetHandleState(struct MACHINE *pmac);
/*
 *
 */
int MacGetSysState(struct MACHINE *pmac, unsigned short *state, unsigned short *reset_state);
/*
 * ÔËÐÐ·´À¡
 */
int MacGetRunFeedback(struct MACHINE *pmac, RUN_FEEDBACK *pfeed_back);
/*
 * set machine type
 */
int MacSendMacType(struct MACHINE *pmac);
/*
*
 */
int MacJustResetJijia(struct MACHINE *pmac, ushort state);
/*
*
 */
int MacResetJijia(struct MACHINE *pmac, ushort state);
/*
*
 */
int MacUpgradeJijia(struct MACHINE *pmac, ushort state);
/*
 * 升级反馈
 */
int MacGetUpgradeFeedback(struct MACHINE *pmac, uchar *state, uchar *percent);
/*
 * send jijia upgrade file
 */
 int MacSendJijiaUpgrade(struct MACHINE *pmac, uchar *data, int file_size);
 /*
 *
 */
 int MacGetSysTime(struct MACHINE *pmac, int* time_set, int *time_add);
  /*
 *
 */
 int MacGetSysId(struct MACHINE *pmac, char* sys_id);



/********************************************************************************
 * modify the param of machine below
 ********************************************************************************/
/*
 * set economy of machine
 */
int MacSetEconomy(struct MACHINE *pmac, unsigned short total, unsigned short start, unsigned short end, unsigned short times);
/*
 * send total cloth
 */
int MacSetClothNum(struct MACHINE *pmac, unsigned short done, unsigned short total);
/*
 * set dumu of machine
 * param f0b1: 0-front, 1-back
 * param which: 0-3
 * param sect: 0-31
 */
int MacSetDumu(struct MACHINE *pmac, unsigned int f0b1, unsigned int which, unsigned int sect, unsigned short dumu);
/*
 * set stop of yarn on machine
 */
int MacSetYarnStop(struct MACHINE *pmac, unsigned int l0r1, unsigned int which, unsigned int sect, unsigned char stop);
/*
 * get needle of motor on machine
 */
int MacGetCurrentNeedle(struct MACHINE *pmac, short *needle);
/*
 * get pulse of motor on machine
 */
int MacGetCurrentPulse(struct MACHINE *pmac, int *pulse);
/*
 * send rock data to machine
 */
int MacSendRockData(struct MACHINE *pmac, PROCK_POS prock_pos);
/*
 * send system param
 */
int MacSendSysParam(struct MACHINE *pmac, PSYS_PARAM psys_param);
/*
 * send work param
 */
int MacSendWorkParam(struct MACHINE *pmac, PWORK_PARAM pwork_param);
/*
 * send work param
 */
int MacSendHideParam(struct MACHINE *pmac, PHIDE_PARAM phide_param);
/*
 * send exchanged yarn
 */
int MacSendExchangedYarn(struct MACHINE *pmac, PYARN_EXCHANGE pyarn_exchange);
/*
 * send one line of control data
 */
int MacSendConLine(struct MACHINE *pmac, PKNIT_PAGE pcon, unsigned short total, unsigned short line);
/*
 * send control data
 */
int MacSendControlData(struct MACHINE *pmac, PKNIT_PAGE pcon, unsigned short total);
/*
 * send flower data
 */
int MacSendFlowerData(struct MACHINE *pmac, unsigned char *pflw, unsigned short width, unsigned short height);
/*
 * send speed param
 */
int MacSendSpeedParam(struct MACHINE *pmac, PMH_SPEED pspeed);
/*
 * send dumu param
 */
int MacSendDumuParam(struct MACHINE *pmac, PMH_DUMU pdumu);
/*
 * send dmbz param
 */
int MacSendDmbzParam(struct MACHINE *pmac, PSTITCH_AMEND psa);
/*
 * send sink param
 */
int MacSendSinkParam(struct MACHINE *pmac, SINK_PIECE psa);
/*
 * send yarnfeeder param
 */
int MacSendYarnFeederParam(struct MACHINE *pmac, YARNFEEDER_PIECE yarndata);
/*
 * send yarn stop
 */
int MacSendYarnStopParam(struct MACHINE *pmac, PYARN_STOP pyarn_stop);
/*
 * send stop line
 */
int MacSendStopLine(struct MACHINE *pmac, unsigned short line);
/*
 * send piece lock
 */
int MacSendPieceLock(struct MACHINE *pmac, unsigned char lock);
/*
 * send extent piece data
 */
int MacSendExtentPieceData(struct MACHINE *pmac, PEXT_PIECE pext_piece);
/*
 *
 */
int MacSendSysData(struct MACHINE *pmac, unsigned char *data, int size, int mask);
/*
 *
 */
int MacSendPartsParam(struct MACHINE *pmac, PMAC_PARAM pmac_param);
/*
 *
 */
int MacSendAlarmMask(struct MACHINE *pmac, PALARM_MASK palarm);
/*
 *
 */
int MacSendBeforeCom(struct MACHINE *pmac, PYARN_BEFORE_NEEDLE pyarn_before_needle);
/*
 * send board set param
 */
 int MacSendBoardParam(struct MACHINE *pmac, PBOARD_PARAM pboard);


/*
 * all of below be which to send by machine
 * all be message of can which is command of yarn, selector...
 *
 */
/*
 * message of can sent by machine about selector
 */
int MacToggleSelect(struct MACHINE *pmac, unsigned char *data, int size);
/*
 *
 */
CARRIAGE * MacCarriageNew(struct MACHINE *pmac,  int handle);
/*
 *
 */
 SINK_SETTING * MacSinkSettingNew(struct MACHINE *pmac);
  /*
 *
 */
 CAM_SETTING * MacCamSettingNew(struct MACHINE *pmac);
/*
 * reset select
 */
int MacResetSelect(struct MACHINE *pmac, unsigned char *data, int size);
/*
 * message of can sent by machine about yarn
 */
int MacToggleYarn(struct MACHINE *pmac, unsigned char *data, int size);
/*
 * reset yarn
 */
int MacResetYarn(struct MACHINE *pmac, unsigned char *data, int size);
/*
 * message of can sent by machine about cam
 */
int MacToggleCam(struct MACHINE *pmac, unsigned char *data, int size);
/*
 * reset cam
 */
int MacResetCam(struct MACHINE *pmac, unsigned char *data, int size);
/*
 * message of can sent by machine about stitch
 */
int MacToggleStitch(struct MACHINE *pmac, unsigned char *data, int size, char id);
/*
 * get state of machine head
 */
int MacGetHeader(struct MACHINE *pmac, HEAD_TEST *phead_test);
/*
 * run rock
 */
int MacRunRock(struct MACHINE *pmac, short pos);
/*
 * reset rock
 */
int MacResetRock(struct MACHINE *pmac, short pos);
/*
 * get version info
 */
int MacGetVersionInfo(struct MACHINE *pmac, VERSION *pversion);
/*
 * @note:·¢ËÍÇ°×º±àÖ¯Êý¾Ý¸øÏÂÎ»»ú,1´Î·¢1ÐÐ
 */
int MacSendPkCon(struct MACHINE *pmac, uchar *pcon, ushort height, uchar type);
/*
 * ·¢ËÍ»¨Ñù¸øÏÂÎ»»ú,1´Î·¢1ÐÐ
 */
int MacSendPkDat(struct MACHINE *pmac, uchar *dat, ushort width, ushort height);






#endif
